const fs=require('fs');
const path=require('path');
let str="";
fs.readdir("./",function(err,files){
    if(err) throw err;
    console.log(files);
    for(var i=0;i<files.length;i++){
        if(files[i].indexOf(".xlsx")!=-1){
            makebtn(files[i]);
        }
    }
})

function makebtn(name){
    name=name.split(".")[0];
    str="";
    str+="chcp 936";
    str+="\r\n@echo off ";
    str+="\r\nif exist \".\\\\script\\\\config.xlsx\" (";
    str+=`\r\n    xcopy .\\${name}.xlsx .\\script\\config.xlsx /y`;
    str+="\r\n    node script\\app.js ";
    str+="\r\n    .\\script\\build.bat";
     str+="\r\n   echo successful";
    str+="\r\n) else (";
    str+=`\r\n    xcopy .\\${name}.xlsx .\\script\\ /y`;
    str+="\r\n    cd .\\script";
    str+=`\r\n    ren ${name}.xlsx config.xlsx`;
    str+="\r\n    node app.js ";
    str+="\r\n    .\\build.bat";
     str+="\r\n   echo successful";
    str+="\r\n)";
    fs.writeFile(`@${name}打包.bat`,str,"utf-8",function(error){
        if(error){
            console.log(error);
            return false;
        }
        console.log('写入成功');
    })
}
